package com.kc.business.service.impl;

import com.kc.business.domain.BizComment;
import com.kc.business.mapper.BizCommentMapper;
import com.kc.business.service.IBizCommentService;
import com.kc.common.utils.JsonUtils;
import com.kc.common.utils.StringUtils;
import com.kc.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Service
public class BizCommentServiceImpl implements IBizCommentService {
    @Autowired
    private BizCommentMapper commentMapper;
    @Autowired
    private ISysDictDataService iSysDictDataService;
    /**
     * 获取列表
     * @param bizComment
     * @return
     */
    @Override
    public List<BizComment> getList(BizComment bizComment) {
        List<BizComment> commentList = commentMapper.select(bizComment);
        commentList.forEach(comment->{
            if(!comment.getImages().equals("")){
                comment.setImagesList(Arrays.asList(StringUtils.split(comment.getImages(),",")));
                //comment.setImagesList(JsonUtils.jsonStringToListString(comment.getImages()));
            }else{
                comment.setImagesList(new ArrayList<>());
            }

            comment.setThemeTypeName(iSysDictDataService.selectDictLabel("theme_type",comment.getThemeType().toString()));
            if(comment.getThemeTypeName() == null){
                comment.setThemeTypeName("");
            }
        });
        return commentList;
    }

    /**
     * 删除评论
     * @param bizComment
     * @return
     */
    @Override
    public Integer remove(BizComment bizComment) {
        return commentMapper.updateByPrimaryKeySelective(bizComment);
    }
}
